package com.psp.park.controller.springmvc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import com.psp.park.controller.res.*;
import com.psp.park.controller.res.bean.*;
import com.psp.park.controller.springmvc.req.*;

/**
 * 订单-相关接口
 **/
@Controller
@RequestMapping(value = "/park/order", produces = "application/json")
public class SOrderController {
	@Autowired
	com.psp.park.controller.OrderController orderController;

	/**
	 * 订单列表
	 **/
	@RequestMapping("/v1/list")
	@ResponseBody
	public ListResult<ROrderListBean> list(@Validated GetOrderListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<ROrderListBean> res = new ListResult<ROrderListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.list(param, request, response);
	}

	/**
	 * 获取订单详情信息
	 **/
	@RequestMapping("/v1/getDetail")
	@ResponseBody
	public ObjectResult<ROrderDetailBean> getDetail(@Validated GetOrderDetailParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<ROrderDetailBean> res = new ObjectResult<ROrderDetailBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.getDetail(param, request, response);
	}

	/**
	 * 获取确认订单中服务
	 **/
	@RequestMapping("/v1/getOrderProduct")
	@ResponseBody
	public ObjectResult<RConfirmOrderProductBean> getOrderProduct(@Validated GetConfirmOrderProductParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ObjectResult<RConfirmOrderProductBean> res = new ObjectResult<RConfirmOrderProductBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.getOrderProduct(param, request, response);
	}

	/**
	 * 辅助下订单
	 **/
	@RequestMapping("/v1/help")
	@ResponseBody
	public BaseResult help(@Validated GetRefuseOrderParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		BaseResult res = new BaseResult();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.help(param, request, response);
	}

	/**
	 * 需求登记
	 **/
	@RequestMapping("/v1/serviceRecordList")
	@ResponseBody
	public ListResult<RParkUserFormServiceRecordListBean> serviceRecordList(@Validated GetParkUserFormRecordListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RParkUserFormServiceRecordListBean> res = new ListResult<RParkUserFormServiceRecordListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.serviceRecordList(param, request, response);
	}

	/**
	 * 合作记录
	 **/
	@RequestMapping("/v1/cooperationRecordList")
	@ResponseBody
	public ListResult<RParkUserFormCooperationRecordListBean> cooperationRecordList(@Validated GetParkUserFormRecordListParam param, BindingResult error, HttpServletRequest request, HttpServletResponse response) {
		ListResult<RParkUserFormCooperationRecordListBean> res = new ListResult<RParkUserFormCooperationRecordListBean>();
		if (error.hasErrors()) {
			res.setRescode(BaseResult.param.getCode());
			res.setMsg(error.getFieldError().getDefaultMessage());
			return res;
		}

		return orderController.cooperationRecordList(param, request, response);
	}
}
